import { ref } from 'vue';
import { Input, message } from 'ant-design-vue';
import { useAuthStore } from '@/store/modules/auth';
import { isNonNegativeInteger } from '@/utils';

let topFormModel;
let bottomFormModel;
const lotType = ref('input');
const lotids = ref([]);
const moduleNoSearchData = ref(null);

const authStore = useAuthStore();
export default {
  url: '/qms/agv/press/plateArrange/list',
  addUrl: '/qms/agv/press/plateArrange/insert',
  editUrl: '/qms/agv/press/plateArrange/update',
  delUrl: '/qms/agv/press/plateArrange/deleteBatch',
  modalGetTableDataUrl: '/qms/agv/press/plateArrange/',
  delMethod: 'put',
  createByKey: 'operater',
  searchFormList: [
    {
      type: 'input',
      key: 'prodNo',
      label: '生产型号',
      placeholder: '请输入生产型号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    },
    {
      type: 'input',
      key: 'lotId',
      label: 'LOT号',
      placeholder: '请输入LOT号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    },
    {
      type: 'input',
      key: 'serialNum',
      label: '单据号',
      placeholder: '请输入单据号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    },
    {
      type: 'select',
      key: 'state',
      label: '审核状态',
      placeholder: '请选择审核状态',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4,
      selectOptions: [
        {
          value: '4',
          label: '待领班审核'
        },
        {
          value: '1',
          label: '待修改'
        },
        {
          value: '2',
          label: '待主管审核'
        },
        {
          value: '3',
          label: '审核完成'
        },
        {
          value: '0',
          label: 'ipqc/工艺审核'
        }
      ]
    },
    {
      type: 'dateRangePicker',
      key: 'time',
      label: '时间',
      span: 24,
      md: 12,
      lg: 10,
      xl: 8,
      xxl: 6
    }
  ],
  searchParam: ref({
    prodNo: null,
    lotId: null,
    state: null,
    time: null
  }),
  showIPQCExamine: true,
  iPQCExamineText: 'IPQC/工艺审核',
  column: [
    {
      key: 'dataIndex',
      dataIndex: 'dataIndex',
      title: '序号',
      width: 70,
      fixed: 'left',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'moduleNo',
      dataIndex: 'moduleNo',
      title: '生产型号',
      width: 150,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'serialNum',
      dataIndex: 'serialNum',
      title: '单据号',
      width: 130,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'thickness',
      dataIndex: 'thickness',
      title: '板厚',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'lotId',
      dataIndex: 'lotId',
      title: 'LOT号',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'state',
      dataIndex: 'state',
      title: '状态',
      width: 120,
      align: 'center',
      checked: true,
      ellipsis: true,
      customRender: ({ record }) => {
        return ['待ipqc/工艺审核', '待修改', '待主管审核', '审核完成', '待领班审核'][record.state];
      }
    },
    {
      key: 'modifyTime',
      dataIndex: 'modifyTime',
      title: '时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'quantity',
      dataIndex: 'quantity',
      title: '数量(PNL)',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'checkItems',
      dataIndex: 'checkItems',
      title: '开料尺寸(MM)',
      width: 400,
      align: 'center',
      checked: true,
      ellipsis: true,
      children: [
        {
          key: 'cuttingLength',
          dataIndex: 'cuttingLength',
          title: '长度',
          width: 100,
          align: 'center',
          checked: true,
          ellipsis: true
        },
        {
          key: 'width',
          dataIndex: 'width',
          title: '宽度',
          width: 100,
          align: 'center',
          checked: true,
          ellipsis: true
        }
      ]
    },

    {
      key: 'numPerLayer',
      dataIndex: 'numPerLayer',
      title: '每层板数',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'perBooks',
      dataIndex: 'perBooks',
      title: '每book层数',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'pressStructure',
      dataIndex: 'pressStructure',
      title: '压合结构',
      width: 145,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'tgValue',
      dataIndex: 'tgValue',
      title: 'TG值',
      width: 110,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'copperScale',
      dataIndex: 'copperScale',
      title: '铜箔规模',
      width: 110,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'numKraftPaper',
      dataIndex: 'numKraftPaper',
      title: '使用牛皮纸张数',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'heatNumber',
      dataIndex: 'heatNumber',
      title: '当班炉号',
      width: 110,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'progammerCode',
      dataIndex: 'progammerCode',
      title: '程序代码',
      width: 110,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'upwardTime',
      dataIndex: 'upwardTime',
      title: '上压时间',
      width: 110,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'coolTime',
      dataIndex: 'coolTime',
      title: '冷压时间',
      width: 110,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'vacuumValue',
      dataIndex: 'vacuumValue',
      title: '真空值',
      width: 110,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'checkItems',
      dataIndex: 'checkItems',
      title: '检查项目',
      align: 'center',
      checked: true,
      ellipsis: true,
      children: [
        {
          title: '铜箔规格',
          dataIndex: 'checkKind1',
          key: 'checkKind1',
          width: 100,
          align: 'center',
          checked: true,
          ellipsis: true
        },
        {
          title: '铜箔厂商',
          dataIndex: 'checkKind2',
          key: 'checkKind2',
          width: 100,
          align: 'center',
          checked: true,
          ellipsis: true
        },
        {
          title: '温度',
          dataIndex: 'checkKind3',
          key: 'checkKind3',
          width: 100,
          align: 'center',
          checked: true,
          ellipsis: true
        },
        {
          title: '压力',
          dataIndex: 'checkKind4',
          key: 'checkKind4',
          width: 100,
          align: 'center',
          checked: true,
          ellipsis: true
        },
        {
          title: '时间',
          dataIndex: 'checkKind5',
          key: 'checkKind5',
          width: 100,
          align: 'center',
          checked: true,
          ellipsis: true
        },
        {
          title: '热压真空度',
          dataIndex: 'checkKind6',
          key: 'checkKind6',
          width: 100,
          align: 'center',
          checked: true,
          ellipsis: true
        }
      ]
    },
    {
      key: 'checkTypes',
      dataIndex: 'checkTypes',
      title: '检查类型',
      width: 400,
      align: 'center',
      checked: true,
      ellipsis: true,
      children: [
        {
          key: 'checkType1',
          dataIndex: 'checkType1',
          title: '首件检查',
          width: 90,
          align: 'center',
          checked: true,
          ellipsis: true
        },
        {
          key: 'checkType2',
          dataIndex: 'checkType2',
          title: '自主检查',
          width: 90,
          align: 'center',
          checked: true,
          ellipsis: true
        },
        {
          key: 'checkType3',
          dataIndex: 'checkType3',
          title: '末件检查',
          width: 90,
          align: 'center',
          checked: true,
          ellipsis: true
        }
      ]
    },

    {
      key: 'foreman',
      dataIndex: 'foreman',
      title: '领班审核',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'qa',
      dataIndex: 'qa',
      title: 'IPQC/工艺审核',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'qaTime',
      dataIndex: 'qaTime',
      title: 'IPQC/工艺审核时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'foremanTime',
      dataIndex: 'foremanTime',
      title: '领班审核时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'examiner',
      dataIndex: 'examiner',
      title: '主管审核',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'examinerTime',
      dataIndex: 'examinerTime',
      title: '主管审核时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'shiftType',
      dataIndex: 'shiftType',
      title: '班别',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true,
      customRender: ({ record }) => {
        return ['白班', '夜班'][record.shiftType];
      }
    },
    {
      key: 'remark',
      dataIndex: 'remark',
      title: '备注',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'createTime',
      dataIndex: 'createTime',
      title: '创建时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'updateTime',
      dataIndex: 'updateTime',
      title: '修改时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'updateBy',
      dataIndex: 'updateBy',
      title: '修改人',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    }
  ],

  scroll: { x: 2500, y: 'auto' },
  topFormList: [
    // 用于获取model
    {
      type: 'getModel',
      hidden: true,
      handle(topModel, personModle) {
        topFormModel = topModel;
        bottomFormModel = personModle;
      }
    },
    {
      type: 'searchInput',
      key: 'lotId',
      label: 'Lot号',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      disabled: false,
      rule: {
        required: true,
        message: '请输入Lot号',
        trigger: 'change'
      },
      searchKey: 'lotId',
      transfromSearch(model, searchData) {
        topFormModel = model;
        moduleNoSearchData.value = searchData;
        Object.keys(model.value).forEach(item => {
          model.value[item] = searchData[item] || model.value[item];
        });
        topFormModel.value.modifyTime = searchData.modifyTime;
        bottomFormModel.value.shiftType = searchData.shiftType;
        topFormModel.value.tgValue = searchData.tgValue;
        topFormModel.value.lotId = searchData.lotId;
        topFormModel.value.moduleNo = searchData.moduleNo;
        topFormModel.value.quantity = searchData.quantity;
        topFormModel.value.pressStructure = searchData.pressStructure;
        topFormModel.value.cuttingLength = searchData.cuttingLength;
        topFormModel.value.width = searchData.cuttingWidth;
        topFormModel.value.numKraftPaper = '5新20旧';
        topFormModel.value.numPerLayer = '2';
        topFormModel.value.vacuumValue = '5mbar';
        topFormModel.value.stage1Temp = '130';
        topFormModel.value.stage1Press = '49.9';
        topFormModel.value.stage2Temp = '150';
        topFormModel.value.stage2Press = '129.8';
        topFormModel.value.stage3Temp = '170';
        topFormModel.value.stage3Press = '129.9';
        topFormModel.value.coolTime = '45min';
        bottomFormModel.value.remark = '首件2块无异常,巡检3次无异常,无漏拉';
      }
    },
    {
      type: 'input',
      key: 'moduleNo',
      label: '生产型号',
      span: 12,

      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      rule: {
        required: true,
        message: '请输入生产型号',
        trigger: 'change'
      }
    },
    {
      type: 'input',
      key: 'quantity',
      label: '数量(PNL)',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      rule: {
        required: true,
        message: '请输入数量(PNL)',
        trigger: 'change'
      }
    },
    {
      type: 'datePicker',
      key: 'modifyTime',
      label: '时间',
      span: 12,
      rule: {
        required: true,
        message: '请选择时间',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      showTime: true
    },
    {
      type: 'input',
      key: 'coolTime',
      label: '冷压时间',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'radio',
      key: 'shiftType',
      label: '班别',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          label: '白班',
          value: '0'
        },
        {
          label: '夜班',
          value: '1'
        }
      ],
      rule: {
        required: true,
        message: '请选择班别',
        trigger: 'blur'
      }
    },
    {
      type: 'input',
      key: 'thickness',
      label: '板厚',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'perBooks',
      label: '每book层数',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'input',
      key: 'operater',
      label: '值机员',
      span: 12,
      defaultValue: authStore.userInfo.user.nickName || authStore.userInfo.user.userName,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'recorder',
      label: '记录员',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'textarea',
      key: 'remark',
      label: '备注',
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      textareaRows: 1,
      span: 24
    },
    {
      type: 'tabs',
      name: '开料尺寸(MM)',
      span: 24
    },

    {
      type: 'input',
      key: 'cuttingLength',
      label: '长',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'width',
      label: '宽',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'tabs',
      name: '生产条件',
      span: 24
    },
    {
      type: 'input',
      key: 'numPerLayer',
      label: '每层排板块数',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'tgValue',
      label: 'TG值',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'textarea',
      key: 'pressStructure',
      label: '压合结构',
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      textareaRows: 1,
      span: 24
    },
    {
      type: 'input',
      key: 'copperScale',
      label: '铜箔规模',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'numKraftPaper',
      label: '使用牛皮纸张数',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'heatNumber',
      label: '当班炉号',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'upwardTime',
      label: '上压时间',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'vacuumValue',
      label: '真空值',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'progammerCode',
      label: '程序代码',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'copperNumUp',
      label: '铜箔卷号—上',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'copperNumDown',
      label: '铜箔卷号—下',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'tabs',
      name: '运行阶段1',
      span: 24
    },
    {
      type: 'input',
      key: 'stage1Temp',
      label: '温度',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'stage1Press',
      label: '压力',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'tabs',
      name: '运行阶段2',
      span: 24
    },
    {
      type: 'input',
      key: 'stage2Temp',
      label: '温度',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'stage2Press',
      label: '压力',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'tabs',
      name: '运行阶段3',
      span: 24
    },
    {
      type: 'input',
      key: 'stage3Temp',
      label: '温度',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'stage3Press',
      label: '压力',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'radio',
      key: 'checkType1',
      label: '首件检查',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      showReset: true,
      selectOptions: [
        {
          label: 'OK',
          value: 'OK'
        },
        {
          label: 'NG',
          value: 'NG'
        }
      ]
    },

    {
      type: 'radio',
      key: 'checkType2',
      label: '自主检查',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      showReset: true,
      selectOptions: [
        {
          label: 'OK',
          value: 'OK'
        },
        {
          label: 'NG',
          value: 'NG'
        }
      ]
    },

    {
      type: 'radio',
      key: 'checkType3',
      label: '末件检查',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      showReset: true,
      selectOptions: [
        {
          label: 'OK',
          value: 'OK'
        },
        {
          label: 'NG',
          value: 'NG'
        }
      ]
    },

    {
      type: 'input',
      key: 'checkNum1',
      label: '首件检查数量',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'checkNum2',
      label: '自主检查数量',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'checkNum3',
      label: '末件检查数量',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'tabs',
      name: '检查项目',
      span: 24
    },
    {
      type: 'input',
      key: 'checkKind1',
      label: '铜箔规格',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'checkKind2',
      label: '铜箔厂商',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'checkKind3',
      label: '温度',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'checkKind4',
      label: '压力',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'checkKind5',
      label: '时间',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'checkKind6',
      label: '热压真空度',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    }
  ],
  bottomList: [
    {
      type: 'input',
      key: 'foreman',
      label: '领班审核',
      disabled: true,
      span: 12
    },
    {
      type: 'input',
      key: 'examiner',
      label: '主管审核',
      disabled: true,
      span: 12
    }
  ],
  modalHeight: '90vh',
  modalTableKey: 'badId',
  modalAddTableKey: 'badDoList',
  modleSearchUrlObj: {
    lotId: '/rcerp/agv/erp/getPress'
  },
  modalGetTableUrlSuffix: {
    add: 'selectBadId',
    byId: 'listBad'
  },
  modalClose() {
    lotType.value = 'input';
    moduleNoSearchData.value = null;
    lotids.value = [];
  }
};
